/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
					     owned_scriptable_adv_object.h

	$Header: /game/owned_scriptable_adv_object.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( OWNED_SCRIPTABLE_ADV_OBJECT_H_INCLUDED )
#define OWNED_SCRIPTABLE_ADV_OBJECT_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <vector>

#include "ownable_event_list.h"
#include "owned_adv_object.h"

// --------------------------------------------------------------------------
// t_owned_scriptable_adv_object class
// --------------------------------------------------------------------------

class t_owned_scriptable_adv_object : public t_owned_adv_object
{
public:
	// Constructor
	explicit t_owned_scriptable_adv_object( std::string const & model_name );

	// Member functions
	virtual int		get_version() const;
	virtual bool	process_triggerable_events( t_adventure_map& map, std::string const& name );
	// This class's read and write functions can stand alone and need not
	// be overridden in derived classes if they add no additional data.
	// However if a derived class does override read and write, it must
	// define its own version number a translate its version number into this
	// class's version number when forwarding the read() call to this class.
	virtual bool	read(
						std::streambuf &					stream,
						t_qualified_adv_object_type const &	type,
						int									version );
	virtual bool	write( std::streambuf & stream ) const;

protected:
	// Member functions
	
	// Copy the event list from one object to another
	static void copy_events( t_owned_scriptable_adv_object & target, t_owned_scriptable_adv_object const & source );

	// This function does not override the virtual read_from_map() function
	// because it accepts an additional format version parameter.  This
	// function is intended to be used in further derived class overrides of
	// read_from_map().
	bool	read_from_map(
				std::streambuf &		stream,
				t_progress_handler *	handler,
				int						version );

private:
	// Types
	typedef t_ownable_triggerable_event			t_triggerable_event;
	typedef t_ownable_triggerable_event_ptr		t_triggerable_event_ptr;
	typedef t_ownable_triggerable_event_list	t_triggerable_event_list;

	// Data members
	t_triggerable_event_list	m_triggerable_events;

	// Member functions
	bool	read_events( std::streambuf & stream, int version );
	bool	read_events_from_map( std::streambuf & stream, int version );
	bool	write_events( std::streambuf & stream ) const;
};

// --------------------------------------------------------------------------
// t_owned_scriptable_adv_object inline members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline t_owned_scriptable_adv_object::t_owned_scriptable_adv_object(
	std::string const &	model_name )
	:	t_owned_adv_object( model_name )
{
}

#endif // !defined( OWNED_SCRIPTABLE_ADV_OBJECT_H_INCLUDED )
